package com.xx.cloud.pay.config;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;

public class HbTableStyle extends AbstractVerticalCellStyleStrategy {

	public HbTableStyle() {
	}

	@Override
	protected WriteCellStyle headCellStyle(Head head) {
		// 头的策略
		WriteCellStyle headWriteCellStyle = new WriteCellStyle();
		// 背景设置为白色
		headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
		WriteFont headWriteFont = new WriteFont();
		headWriteFont.setFontHeightInPoints((short)16);
		headWriteCellStyle.setWriteFont(headWriteFont);
		return headWriteCellStyle;
	}

	@Override
	protected WriteCellStyle contentCellStyle(Head head) {
		// 内容的策略
		WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
		// 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
		contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);

		//设置边框
		this.setBorderStyle(contentWriteCellStyle);

		//居中
		contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
		// 背景白色
		contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());

		WriteFont contentWriteFont = new WriteFont();
		// 字体大小
		contentWriteFont.setFontHeightInPoints((short)12);
		contentWriteCellStyle.setWriteFont(contentWriteFont);
		return contentWriteCellStyle;
	}


	private static void setBorderStyle(WriteCellStyle contentWriteCellStyle){
		//设置边框样式
		contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
		contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
		contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
		contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
	}
}
